//
//  MainTabBar.swift
//  iOS07-Weibo-LPK
//
//  Created by 罗培克 on 6/23/15.
//  Copyright © 2015 lpk. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    let buttonCount = 5
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let w = bounds.width / CGFloat(buttonCount)
        let rect = CGRectMake(0, 0, w, bounds.height)
        
        var index = 0
        for v in subviews {
            if v is UIControl && !(v is UIButton) {
                
                (v as! UIControl).frame = CGRectOffset(rect, CGFloat(index) * w, 0)
//                index++
                //            if index == 2 {
                //                index++
                //            }
                index += index == 1 ? 2 : 1
            }
        }
        
        composeButton.frame = CGRectOffset(rect, 2.0 * w, 0)
    }
    
    lazy var composeButton: UIButton = {
        let btn = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        self.addSubview(btn)
        
        return btn
    }()
}
